<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>GetFileTime</title>
<meta http-equiv="Content-Type" Content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="../../styles/styles.css">
<script language="javascript" src='../links.js' type="text/javascript"></script>
</head>

<body>

<h1>GetFileTime</h1>
<div class=navbar>
<a href="../index.html">main</a> |
<a href="../structures/index.html">structures</a> |
<a href="index.html">win32 structures</a>
</div>

<div class=shortdescr>
The <dfn>GetFileTime</dfn> function retrieves the date and time that a file was created, last
accessed, and last modified.
</div>

<pre class=syntax>
BOOL GetFileTime(
  HANDLE hFile,
  CONST FILETIME *lpCreationTime,
  CONST FILETIME *lpLastAccessTime,
  CONST FILETIME *lpLastWriteTime
);
</pre>

<h3>Parameters</h3>
<div class=descr>

    <div class=dfn>hFile</div>
    <div class=dfndescr>Handle to the file for which to get dates and times. The file handle must
      have been created with the GENERIC_READ access to the file.</div>
    <div class=dfn>lpCreationTime</div>
    <div class=dfndescr>Pointer to a <a href="filetime.html">FILETIME</a> structure to receive the
      date and time the file was created. This parameter can be NULL if the application does not
      require this information.</div>
    <div class=dfn>lpLastAccessTime</div>
    <div class=dfndescr>Pointer to a <a href="filetime.html">FILETIME</a> structure to receive the
      date and time the file was last accessed. The last access time includes the last time the file
      was written to, read from, or, in the case of executable files, run. This parameter can be NULL
      if the application does not require this information.</div>
    <div class=dfn>lpLastWriteTime</div>
    <div class=dfndescr>Pointer to a <a href="filetime.html">FILETIME</a> structure to receive the
      date and time the file was last written to. This parameter can be NULL if the application does
      not require this information.</div>

</div>

<h3>Return value</h3>
<div class=descr>
If the function succeeds, the return value is nonzero.<br>

If the function fails, the return value is zero. To get extended error information, call
<a href="win32/GetLastError">GetLastError</a>.
</div>

<h3>Remarks</h3>
<div class=descr>

  <p>The FAT and NTFS file systems support the file creation, last access, and last write time
     values.</p>

  <p class=note><img src="../../images/note.gif" alt="Time precision" width="10" height="10"> Time precision</p>
  <UL class=note><LI>
   The file time precision can vary depending on operating system, file system, network configuration.
See remarks for the <a href="filetime.html#precise">FILETIME</a> for details.
  </LI></UL>

  <p class=note><img src="../../images/note.gif" alt="A note for Windows NT" width="10" height="10"> Windows NT family</p>
  <UL class=note><LI>
  When Windows NT creates a list of folders (e.g. DIR command) in a NTFS volume, it modifies last
  access date/time for all found folders. It can degrade effectiveness if the number of folders is
  very large.<br>
  This behaviour can be controled, see
  <a href="http://www.winguides.com/registry/display.php/50/" target="_blank">Disable the NTFS Last Access Time Stamp</a>
  for details.
<!--
Key: [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
Name: NtfsDisableLastAccessUpdate
Type: REG_DWORD
Value: (0 = off, 1 = on)
-->
</li>
<li>
If you rename or delete a file, then restore it shortly thereafter, Windows NT searches
the cache for file information to restore. Cached information includes its short/long name
pair and creation time.
</li>
  </UL>
</div>


<h3>Example</h3>
<div class=descr>
The following example demonstrates how to retrieve last-write time for a file in string form
(Windows NT/2000).

<pre class=code>BOOL GetLastWriteTime(HANDLE hFile, LPSTR lpszString)
{
  FILETIME ftCreate, ftAccess, ftWrite;
  SYSTEMTIME stUTC, stLocal;

  // get file time and date
  if (!GetFileTime(hFile, &amp;ftCreate, &amp;ftAccess, &amp;ftWrite))
      return FALSE;

  // convert modification time to local time.
  FileTimeToSystemTime(&amp;ftWrite, &amp;stUTC);
  SystemTimeToTzSpecificLocalTime(NULL, &amp;stUTC, &amp;stLocal);

  // convert retrieved time to string
  wsprintf(lpszString, "%02d/%02d/%d  %02d:%02d",
      stLocal.wDay, stLocal.wMonth, stLocal.wYear,
      stLocal.wHour, stLocal.wMinute);

  return TRUE;
}
</pre>
</div>


<div class=see>See also:</div><div class=seecont>
<a href="filetime.html">FILETIME</a>,
<a href="win32/GetFileSize">GetFileSize</a>,
<a href="setfiletime.html">SetFileTime</a>,
<a href="win32/GetFileType">GetFileType</a>
</div>

</body>
</html>